<?php
	function imagesize($filename)
	{
		if (($size = @getimagesize($filename)) == true)
		{
			$W = $size[0];
			$H = $size[1];
			return 'width="'.$W.'" height="'.$H.'"';
		}
		return "";
	}
	
	function deal ($dir)
	{
		echo '<h2>'.$dir.'</h2>';
		if (($dp = opendir($dir)) != false)
		{
			$list = array();
			while (($file = readdir($dp)) != false)
			{
				$full = $dir.$file;
				if ($file[0] != ".") // pas prendre . ni ..
				{
					if(is_dir($full))
						$listdir[] = $full;
					else
						$list[$file] = filemtime($full);
				}
			}
			closedir($dp);
			ksort($list);
			foreach ($list as $file => $time)
			{
				$full = $dir.'/'.$file;
				$avatar_size = imagesize($full);
				$file_size = (int)(filesize($full)/1024);
				$avatar_name = substr($full,strrpos($full,'/')+1);
				echo '<img src="'.$full.'" '.$avatar_size.' title="'.$avatar_name.' - '.$file_size.'ko"> ';
			}
		}
		
		if(isset($listdir))
		{
			sort($listdir);
			foreach ($listdir as $full)
				deal($full.'/');
		}
	}
	
	deal("avatars/");
?>